import Url2File from '../unit/Url2File.js'
import SwapWnB from './swapWnB.js'
const OS = {
  SetToken: function (token, expire) {
    localStorage.setItem('UserToken', token)
    if (expire != null) {
      localStorage.setItem('UserTokenExpire', expire)
    }
  },
  GetToken: function () {
    const token = localStorage.getItem('UserToken')
    //dev
    return token != null ? token : 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYmYiOjE3MDQ3ODYzMjQsImNoYW5uZWxNZW1iZXJJZCI6MTY1MjAsImV4cCI6MTcwNzM3ODMyNCwiaWF0IjoxNzA0Nzg2MzI0LCJjaGFubmVsSWQiOjYsIm1lbWJlcklkIjozMX0.QdEtP7_zYSgwzQnKF89JlHeJyaDFeXdrSwZ7JO1gvcA'
    //onlie
    //return token != null ? token : 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYmYiOjE3MDkwMTQ2MjIsImNoYW5uZWxNZW1iZXJJZCI6MTY1MTYsImV4cCI6MTcxMDMxMDYyMiwiaWF0IjoxNzA5MDE0NjIyLCJjaGFubmVsSWQiOjYsIm1lbWJlcklkIjo2fQ.t2gV6JT1a5GQH5aFcHULOiRDNPVgZSH5-vM0ArvAymU'
  },
  Url2File: function( url, callback ){
    Url2File.imgUrlToFile(url, callback)
  },
  GetUrlFileName: function (url){
    return Url2File.getBaseFileName(url)
  },
  ImageToBase64: function(url,callback){
    var imgLink = url
    var tempImage = new Image();
    tempImage.crossOrigin = "*";
    tempImage.referrerpolicy = 'no-referrer'
    tempImage.onload = function() {
      //console.log(tempImage)
      var base64 = Url2File.getBase64Image(tempImage)
      callback(base64);
    };
    tempImage.src = imgLink;
  },
  SwapImgWBColor: function(url,callback){
    //console.log(url)
    this.ImageToBase64(url,function(data){
      SwapWnB.swap(data,function(data_2){
        //console.log(data_2);
        callback(data_2);
      });
    })
  },
  GetFormSetting: function(setting){
    var obj = {
      advanceMode: setting.advanceMode,//智能二创，使用高级模式；
      describe: setting.describe,//文生图、智能二创、换背景，文字描述
      faceImage: setting.faceImage,//换脸，人脸图
      fourImage: setting.fourImage,//未知
      operationId: setting.operationId,//工具ID，详见tool_wapper
      operationName: setting.operationName,//工具名称，详见tool_wapper,
      originalImage: setting.originalImage,//智能二创，换脸，换背景，高清还原，抠图 的原始图片
      promptList: setting.promptList,//文生图、智能二创、换背景的Prompt选项[{index: 0, selectVal: {name: "卡通绘画", prompt: "--niji 6", index: 1, promptIdx: 0}}]
      promptValue: setting.promptValue,//所有选项用于展示的标签，格式如:["卡通绘画", "手绘风格", "全身", "水面"]
      reduciNum: setting.reduciNum,//智能二创还原度设置，
      tabId: setting.tabId,//文生图、智能二创、换背景的Prompt选项，选择的Tab对应的ID
      tabName: setting.tabName,//文生图、智能二创、换背景的Prompt选项，选择的Tab对应的名称
      useAi: setting.useAi//智能二创，是否使用智能描述
    }
    return JSON.stringify(obj)
  }
}

export default OS
